using System.Drawing;
using System.Drawing.Drawing2D;

namespace Demo
{
    internal static class IconFactory
    {
        public static Image SaveIcon { get; } = CreateSaveIcon();
        public static Image DeleteIcon { get; } = CreateDeleteIcon();
        public static Image RefreshIcon { get; } = CreateRefreshIcon();
        public static Image AddIcon { get; } = CreateAddIcon();
        public static Image EditIcon { get; } = CreateEditIcon();
        public static Image ExportIcon { get; } = CreateExportIcon();
        public static Image ReportExportIcon { get; } = CreateReportExportIcon();
        public static Image ReportViewIcon { get; } = CreateReportViewIcon();

        private static Bitmap CreateSaveIcon()
        {
            var bmp = CreateBaseBitmap();
            using var g = Graphics.FromImage(bmp);
            g.SmoothingMode = SmoothingMode.AntiAlias;

            var body = new Rectangle(2, 3, 12, 11);
            using (var brush = new SolidBrush(Color.FromArgb(33, 150, 243)))
            {
                g.FillRectangle(brush, body);
            }

            using (var brush = new SolidBrush(Color.White))
            {
                g.FillRectangle(brush, new Rectangle(4, 5, 8, 5));
                g.FillRectangle(brush, new Rectangle(4, 11, 8, 2));
            }

            using (var pen = new Pen(Color.FromArgb(25, 118, 210), 1))
            {
                g.DrawRectangle(pen, body);
            }

            return bmp;
        }

        private static Bitmap CreateDeleteIcon()
        {
            var bmp = CreateBaseBitmap();
            using var g = Graphics.FromImage(bmp);
            g.SmoothingMode = SmoothingMode.AntiAlias;

            using (var brush = new SolidBrush(Color.FromArgb(229, 57, 53)))
            {
                g.FillEllipse(brush, new Rectangle(2, 2, 12, 12));
            }

            using (var pen = new Pen(Color.White, 2))
            {
                g.DrawLine(pen, 5, 5, 11, 11);
                g.DrawLine(pen, 11, 5, 5, 11);
            }

            return bmp;
        }

        private static Bitmap CreateRefreshIcon()
        {
            var bmp = CreateBaseBitmap();
            using var g = Graphics.FromImage(bmp);
            g.SmoothingMode = SmoothingMode.AntiAlias;

            using (var pen = new Pen(Color.FromArgb(30, 136, 229), 2))
            {
                pen.StartCap = LineCap.Round;
                pen.EndCap = LineCap.Round;
                g.DrawArc(pen, new Rectangle(3, 3, 10, 10), 45, 270);
            }

            using (var path = new GraphicsPath())
            {
                path.AddPolygon(new[] { new Point(8, 2), new Point(12, 2), new Point(10, 6) });
                using var brush = new SolidBrush(Color.FromArgb(30, 136, 229));
                g.FillPath(brush, path);
            }

            return bmp;
        }

        private static Bitmap CreateAddIcon()
        {
            var bmp = CreateBaseBitmap();
            using var g = Graphics.FromImage(bmp);
            g.SmoothingMode = SmoothingMode.AntiAlias;

            using (var brush = new SolidBrush(Color.FromArgb(76, 175, 80)))
            {
                g.FillEllipse(brush, new Rectangle(2, 2, 12, 12));
            }

            using (var pen = new Pen(Color.White, 2))
            {
                pen.StartCap = LineCap.Round;
                pen.EndCap = LineCap.Round;
                g.DrawLine(pen, 8, 5, 8, 11);
                g.DrawLine(pen, 5, 8, 11, 8);
            }

            return bmp;
        }

        private static Bitmap CreateEditIcon()
        {
            var bmp = CreateBaseBitmap();
            using var g = Graphics.FromImage(bmp);
            g.SmoothingMode = SmoothingMode.AntiAlias;

            using (var pen = new Pen(Color.FromArgb(255, 202, 40), 6))
            {
                pen.StartCap = LineCap.Round;
                pen.EndCap = LineCap.Round;
                g.DrawLine(pen, 4, 12, 12, 4);
            }

            using (var pen = new Pen(Color.FromArgb(66, 66, 66), 1))
            {
                g.DrawRectangle(pen, new Rectangle(2, 10, 6, 4));
            }

            return bmp;
        }

        private static Bitmap CreateExportIcon()
        {
            var bmp = CreateBaseBitmap();
            using var g = Graphics.FromImage(bmp);
            g.SmoothingMode = SmoothingMode.AntiAlias;

            using (var pen = new Pen(Color.FromArgb(38, 166, 154), 2))
            {
                g.DrawRectangle(pen, new Rectangle(3, 4, 10, 8));
            }

            using (var brush = new SolidBrush(Color.FromArgb(38, 166, 154)))
            {
                g.FillPolygon(brush, new[] { new Point(8, 2), new Point(12, 6), new Point(10, 6), new Point(10, 12), new Point(6, 12), new Point(6, 6), new Point(4, 6) });
            }

            return bmp;
        }

        private static Bitmap CreateReportExportIcon()
        {
            var bmp = CreateBaseBitmap();
            using var g = Graphics.FromImage(bmp);
            g.SmoothingMode = SmoothingMode.AntiAlias;

            var page = new Rectangle(3, 2, 10, 12);
            using (var brush = new SolidBrush(Color.FromArgb(245, 245, 245)))
            {
                g.FillRectangle(brush, page);
            }

            using (var pen = new Pen(Color.FromArgb(96, 125, 139), 1))
            {
                g.DrawRectangle(pen, page);
                g.DrawLine(pen, 5, 6, 11, 6);
                g.DrawLine(pen, 5, 8, 11, 8);
                g.DrawLine(pen, 5, 10, 9, 10);
            }

            using (var brush = new SolidBrush(Color.FromArgb(76, 175, 80)))
            {
                g.FillPolygon(brush, new[] { new Point(8, 12), new Point(12, 12), new Point(10, 15) });
            }

            return bmp;
        }

        private static Bitmap CreateReportViewIcon()
        {
            var bmp = CreateBaseBitmap();
            using var g = Graphics.FromImage(bmp);
            g.SmoothingMode = SmoothingMode.AntiAlias;

            var page = new Rectangle(3, 2, 10, 12);
            using (var brush = new SolidBrush(Color.FromArgb(248, 248, 248)))
            {
                g.FillRectangle(brush, page);
            }

            using (var pen = new Pen(Color.FromArgb(96, 125, 139), 1))
            {
                g.DrawRectangle(pen, page);
                g.DrawLine(pen, 5, 6, 11, 6);
                g.DrawLine(pen, 5, 8, 11, 8);
                g.DrawLine(pen, 5, 10, 9, 10);
            }

            using (var pen = new Pen(Color.FromArgb(33, 150, 243), 2))
            {
                g.DrawEllipse(pen, new Rectangle(6, 8, 6, 6));
                pen.EndCap = LineCap.Round;
                pen.StartCap = LineCap.Round;
                g.DrawLine(pen, 10, 12, 12, 14);
            }

            return bmp;
        }

        private static Bitmap CreateBaseBitmap()
        {
            var bmp = new Bitmap(16, 16);
            bmp.SetResolution(96, 96);
            using var g = Graphics.FromImage(bmp);
            g.Clear(Color.Transparent);
            return bmp;
        }
    }
}
